async function getDays(term0, term1) {
	console.log(term0)
	var [err, res] = await uni.request({
		url: 'http://211.82.48.36/student/courseSelect/calendarSemesterCurriculum/index',
	});

	if (res.data.indexOf("登录") != -1) return null
	
	let pat = "(?<=thisSemesterCurriculum/)(.*\n?)(?=/ajaxStudentSchedule)"
	let token = res.data
	token = token.match(pat)[0]

	var [err, res] = await uni.request({
		url: "http://211.82.48.36/student/courseSelect/thisSemesterCurriculum/" + token +
			"/ajaxStudentSchedule/past/callback",
		data: "&planCode=" + term0 + term1,
		method: "POST",
		header: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
	})
	if (err) return null
	// console.log(res)
	let days = []
	let content = res.data
	for (let i = 0; i < 7; i++) days.push([])
	let list = content.dateList[0].selectCourseList
	console.log(list)
	for (let i = 0; i < list.length; i++) {
		let value = list[i]
		let teacher = value.attendClassTeacher
		let newList = value.timeAndPlaceList
		if (Array.isArray(newList)) {
			for (let j = 0; j < newList.length; j++) {
				let newValue = newList[j]
				let name = newValue.coureName
				let startClass = newValue.classSessions
				let length = newValue.continuingSession
				let weeks = newValue.weekDescription.split('周')[0]
				let classDay = newValue.classDay
				let startWeek, endWeek;
				if (weeks.indexOf('-') != -1) {
					startWeek = weeks.split('-')[0]
					endWeek = weeks.split('-')[1]
				} else {
					startWeek = weeks.split('第')[1]
					endWeek = startWeek
				}
				startWeek = parseInt(startWeek)
				endWeek = parseInt(endWeek)				
				let where = newValue.teachingBuildingName + newValue.classroomName
				days[classDay].push({
					name,
					teacher,
					startClass,
					length,
					startWeek,
					endWeek,
					where
				})
			}
		}
	}
	// console.log(days)
	return kebiaoFormat(days)
}

function kebiaoFormat(e) {
	let zhou = new Array();
	for (let i = 0; i < 7; i++) {
		let tian = new Array(10)
		for (let j = 0; j < 10; j++) tian[j] = new Array()

		for (let k = 0; k < e[i].length; k++) {
			let obj = e[i][k];
			tian[obj.startClass - 1].push(obj)
		}
		zhou.push(tian);
	}

	return zhou;
}


export {
	getDays
}
